#include <algorithm>
#include <string>
#include <cstdio>
#define maxn 100005
using namespace std;
int n;
int arr1[maxn], arr2[maxn], dp[maxn];
/**
 * 
 * 例子,分析问题的结构
 * dp[i,j]表:
 *      3   2   1   4   5
 *  1   0   0   1   1   1
 *  2   0   1   1   1   1
 *  3   1   1   1   1   1
 *  4   1   1   1   2   2   
 *  5   1   1   1   2   3
 * 
 *  dp[i,j]表示arr1[1...i]与arr2[1...j]的最长公共子序列的长度
 *  如果arr1[i]==arr2[j]那么dp[i,j]=dp[i-1,j-1]+1
 *  要不然dp[i,j] = max(dp[i,j-1],dp[i-1,j])
 * 
 * 
 */
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &arr1[i]);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &arr2[i]);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
        {
            if (arr1[i] == arr2[j])
                dp[j] = dp[j - 1] + 1;
            else
                dp[j] = max(dp[j - 1], dp[j]);
        }
    printf("%d\n", dp[n]);
    return 0;
};